<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item>
        <label style="color: green;">同步弘新能源设备类型</label>
      </el-form-item>
      <el-form-item label="类型" prop="productTypeSn">
          <el-select
            v-model="queryParams.productTypeSn"
            placeholder="请输入类型SN"
            clearable
            class="!w-120px"
          >
            <el-option
              v-for="dict in getStrDictOptions(DICT_TYPE.METER_PRODUCT_TYPE)"
              :key="(dict.value)"
              :label="dict.label"
              :value="(dict.value)"
            />
          </el-select>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button
          type="primary"
          plain
          @click="sync"
          v-hasPermi="['zwsj:meter-hxny-dict:sync']"
        ><Icon icon="ep:refresh" />同步设备类型</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column type="expand">
      <template #default="props">
        <div m="4">
          <p m="t-0 b-2">厂家: {{ props.row.manufacturerAme }}</p>
          <p m="t-0 b-2">厂家SN: {{ props.row.manufacturerSn }}</p>
          <p m="t-0 b-2">通信协议: {{ props.row.protocolTypeName }}</p>
          <p m="t-0 b-2">通信协议SN: {{ props.row.protocolTypeIdSn }}</p>
          <p m="t-0 b-2">通信方式: {{ props.row.communicationModeSnName }}</p>
          <p m="t-0 b-2">通信方式SN: {{ props.row.communicationModeSn }}</p>
          <p m="t-0 b-2">型号编码: {{ props.row.productNumber }}</p>
          <p m="t-0 b-2">采集器类型: {{ props.row.collectorTypeShow }}</p>
          <p m="t-0 b-2">采集器类型代码: {{ props.row.collectorType }}</p>
          <p m="t-0 b-2">电表类别: {{ props.row.deviceCategoryName }}</p>
          <p m="t-0 b-2">电表类别代码: {{ props.row.deviceCategory }}</p>
          <p m="t-0 b-2">电表类型: {{ props.row.electricPriceTypeName }}</p>
          <p m="t-0 b-2">电表类型代码: {{ props.row.electricPriceType }}</p>
        </div>
      </template>
    </el-table-column>
      <el-table-column label="主键" align="center" prop="id" width="180"/>
      <el-table-column label="类型" align="center" prop="productTypeName" width="80"/>
      <el-table-column label="类型SN" align="center" prop="productTypeSn" width="80"/>
      <!-- <el-table-column label="厂家" align="center" prop="manufacturerAme" />
      <el-table-column label="厂家SN" align="center" prop="manufacturerSn" /> -->
      <el-table-column label="型号名称" align="left" prop="name" />
      <el-table-column label="通信协议" align="center" prop="protocolTypeName" width="120"/>
      <!-- <el-table-column label="通信协议SN" align="center" prop="protocolTypeIdSn" /> -->
      <el-table-column label="通信方式" align="center" prop="communicationModeSnName" width="80"/>
      <!-- <el-table-column label="通信方式SN" align="center" prop="communicationModeSn" /> -->
      <!-- <el-table-column label="型号编码" align="center" prop="productNumber" /> -->
      <el-table-column label="采集器类型" align="center" prop="collectorTypeShow" width="170"/>
      <!-- <el-table-column label="采集器类型代码" align="center" prop="collectorType" /> -->
      <el-table-column label="电表类别" align="center" prop="deviceCategoryName" width="80"/>
      <!-- <el-table-column label="电表类别代码" align="center" prop="deviceCategory" /> -->
      <el-table-column label="电表类型" align="center" prop="electricPriceTypeName" width="170"/>
      <!-- <el-table-column label="电表类型代码" align="center" prop="electricPriceType" /> -->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>

<script setup lang="ts">
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
import { MeterHxnyDictApi, MeterHxnyDictVO } from '@/api/zwsj/meterhxnydict'

/** 弘新能源-字典 列表 */
defineOptions({ name: 'MeterHxnyDict' })

const loading = ref(true) // 列表的加载中
const list = ref<MeterHxnyDictVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  productTypeSn: undefined,
  name: undefined
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await MeterHxnyDictApi.getMeterHxnyDictPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/**同步 */
const sync = async () => {
  ElMessageBox.confirm('该操作将会同步信息，确定继续?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'info'
  })
    .then(() => {
      MeterHxnyDictApi.syncMeterHxnyDict().then( (data)  => {
        if(data){
          handleQuery()
        }
      })
    })
    .catch(() => {
    })
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>